package com.ddwl.order.job;

import com.ddwl.order.service.*;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 类OrderExpirationCloseJob.java的实现描述：订单过期定时任务
 *
 * @author zach
 * @Date :2020-06-12 12:38.
 */
@Component
public class OrderJob {

    @Resource
    private OrderInfoServer orderInfoServer;
    @Resource
    private AfterSaleOrderServer afterSaleOrderServer;
    @Resource
    private ShopAfterSaleOrderServer shopAfterSaleOrderServer;
    @Resource
    private SeckillService seckillService;
    @Resource
    private StatisticsServer statisticsServer;
    @Resource
    private BacklogServer backlogServer;

    /**
     * 订单过期任务
     * 
     */
    @XxlJob("orderExpirationJob")
    public ReturnT<String> demoJobHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行订单关闭任务");
        orderInfoServer.orderAutoClosed();
        return ReturnT.SUCCESS;
    }


    /**
     * 订单自动收货
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("autoReceive")
    public ReturnT<String> autoReceive(String param) throws Exception {
        XxlJobLogger.log("开始执行订单自动收货任务");
        orderInfoServer.autoReceive();
        return ReturnT.SUCCESS;
    }


    /**
     * 外送订单自动收货
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("wsAutoReceive")
    public ReturnT<String> wsAutoReceive(String param) throws Exception {
        XxlJobLogger.log("开始执行订单自动收货任务");
        orderInfoServer.autoLocalReceive();
        return ReturnT.SUCCESS;
    }

    /**
     * 自提订单自动收货
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("ztAutoReceive")
    public ReturnT<String> ztAutoReceive(String param) throws Exception {
        XxlJobLogger.log("开始执行订单自动收货任务");
        orderInfoServer.autoZtReceive();
        return ReturnT.SUCCESS;
    }


    /**
     * 订单过期任务
     *
     */
    @XxlJob("afterSaleOrderExpirationJob")
    public ReturnT<String> afterSaleJobHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行售后订单关闭任务");
        afterSaleOrderServer.orderAutoClosed();
        return ReturnT.SUCCESS;
    }

    /**
     * 自动退款任务
     *
     */
    @XxlJob("afterSaleAutoRefundJob")
    public ReturnT<String> afterSaleAutoRefundHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行自动退款任务");
        shopAfterSaleOrderServer.afterSaleAutoRefund();
        return ReturnT.SUCCESS;
    }

    /**
     * 上架秒杀商品任务
     *
     */
    @XxlJob("uploadSeckillItemJob")
    public ReturnT<String> uploadSeckillItemHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行秒杀商品上架任务");
        seckillService.uploadSeckillItem();
        return ReturnT.SUCCESS;
    }

    /**
     * 释放秒杀商品库存任务
     *
     */
    @XxlJob("releaseLockStockJob")
    public ReturnT<String> releaseLockStockHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行释放秒杀商品库存任务");
        seckillService.releaseLockStock("");
        return ReturnT.SUCCESS;
    }

    /**
     * 数据统计发送消息定时任务
     *
     */
    @XxlJob("sentStatisticsMsgJob")
    public ReturnT<String> sentStatisticsMsgHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行数据统计发送消息定时任务");
        statisticsServer.sentStatisticsMsg();
        return ReturnT.SUCCESS;
    }

    /**
     * 发送待办事项定时任务
     *
     */
    @XxlJob("sendBackLogMsgJob")
    public ReturnT<String> sendBackLogMsgHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行数据统计发送消息定时任务");
        backlogServer.sendBackLogMsg();
        return ReturnT.SUCCESS;
    }

    /**
     * 未发货订单消息定时任务
     *
     */
    @XxlJob("sendShopUnsendMsgJob")
    public ReturnT<String> sendShopUnsentMsgHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行未发货订单消息定时任务");
        orderInfoServer.sendUnsendMsg();
        return ReturnT.SUCCESS;
    }


    /**
     * 删除快麦调用日志定时任务
     *
     */
    @XxlJob("deleteKuiamaiLogJob")
    public ReturnT<String> deleteKuiamaiLogHandler(String param) throws Exception {
        XxlJobLogger.log("开始执行数据删除定时任务");
        backlogServer.deleteKuiamaiLog();
        return ReturnT.SUCCESS;
    }

}
